package com.itcam.cocomate.once;

import com.itcam.cocomate.mapper.UserMapper;
import com.itcam.cocomate.model.domain.User;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.StopWatch;

import javax.annotation.Resource;

/**
 * @author : Cammy.Wu
 * Description : 模拟1000万个用户，再去查询
 */

public class InsertUsers {

    @Resource
    private UserMapper userMapper;

    /**
     * 批量插入用户
     */
//    @Scheduled(initialDelay = 5000, fixedRate = Long.MAX_VALUE)
    public void doInsertUsers() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        final int INSERT_NUMBER = 10000000;
        for (int i = 0; i < INSERT_NUMBER; i++) {
            User user = new User();
            user.setUsername("fake_user" + i);
            user.setUserAccount("fake_user_account" + i);
            user.setAvatarUrl("http://www.example.com/images/fake.jpg");
            user.setGender(0);
            user.setUserPassword("12345678");
            user.setPhone("13211xxxxxx");
            user.setEmail("123456qq@163.com");
            user.setTags("[]");
            user.setUserStatus(0);
            user.setUserRole(0);
            user.setPlanetCode("123456");
        }
        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());
    }
}
